from PyQt6.QtGui import *
from PyQt6.QtCore import *
from PyQt6.QtWidgets import *

class login_Widget(QWidget):

    loginSignal = pyqtSignal()
    tryLoginSignal =  pyqtSignal(str, str)

    def __init__(self):
        super().__init__()


        self.userNameLabel = QLabel("用户名：")
        self.userNameText = QLineEdit()
        self.passwordLabel = QLabel("密码：")
        self.passwordText = QLineEdit()

        self.loginButton = QPushButton("登录")
        self.signupButton = QPushButton("注册")

        self.loginButton.clicked.connect(self.loginAct)

        frameLayout = QGridLayout(self)
        frameLayout.addWidget(self.userNameLabel, 0, 0, 1, 1)
        frameLayout.addWidget(self.userNameText, 0, 1, 1, 3)
        frameLayout.addWidget(self.passwordLabel, 1, 0, 1, 1)
        frameLayout.addWidget(self.passwordText, 1, 1, 1, 3)

        frameLayout.addWidget(self.loginButton, 2, 1, 1, 1)
        frameLayout.addWidget(self.signupButton, 2, 2, 1, 1)
        self.setLayout(frameLayout)

    def loginAct(self):
        self.tryLoginSignal.emit(self.userNameText.text(), self.passwordText.text())

    def getUsername(self):
        return self.userNameText.text()


